<script setup>
import { RouterLink, RouterView } from 'vue-router'
import LoginModal from './components/LoginModal.vue'
import { ref } from 'vue'

// 控制登录模态框显示状态
const isLoginModalVisible = ref(false)

// 显示登录模态框
const showLoginModal = () => {
  isLoginModalVisible.value = true
}

// 关闭登录模态框
const closeLoginModal = () => {
  isLoginModalVisible.value = false
}

// 处理登录事件
const handleLogin = (credentials) => {
  console.log('登录凭证:', credentials)
  // 在实际应用中，这里会有登录逻辑
  closeLoginModal()
}
</script>

<template>
  <!-- 顶部登录按钮区域 - 居中对齐 -->
  <div class="top-login-area">
    <button class="header-login-button" @click="showLoginModal">
      登录
    </button>
  </div>

  <!-- 导航栏区域 -->
  <header>
    <div class="wrapper">
      <nav>
        <RouterLink to="/">首页</RouterLink>
        <RouterLink to="/about">关于</RouterLink>
      </nav>
    </div>
  </header>

  <!-- 主内容区域 -->
  <main class="main-content">
    <RouterView />
  </main>
  
  <!-- 登录模态框组件 -->
  <LoginModal 
    :visible="isLoginModalVisible"
    @close="closeLoginModal"
    @login="handleLogin"
  />
</template>

<style scoped>
/* 全局样式重置和基础设置 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* 应用容器样式 */
#app {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  max-width: 1400px;
  margin: 0 auto;
  background-color: #f5f5f5;
  min-height: 100vh;
}

body {
  margin: 0;
  min-width: 320px;
  background-color: #f5f5f5;
  color: #333;
  line-height: 1.6;
}

/* 顶部登录按钮区域 - 居中对齐 */
.top-login-area {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 1rem 0;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* 登录按钮样式美化 */
.header-login-button {
  padding: 0.75rem 2rem;
  background-color: rgba(255, 255, 255, 0.9);
  color: #667eea;
  border: none;
  border-radius: 30px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.header-login-button:hover {
  background-color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* 导航栏区域样式 */
header {
  background-color: white;
  padding: 1.5rem 0;
  border-bottom: 1px solid #e0e0e0;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.wrapper {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* 导航链接样式美化 */
nav {
  text-align: center;
}

nav a {
  display: inline-block;
  padding: 0.75rem 2rem;
  color: #666;
  text-decoration: none;
  font-size: 1.1rem;
  font-weight: 500;
  transition: all 0.3s ease;
  position: relative;
  margin: 0 0.5rem;
}

nav a:hover {
  color: #667eea;
}

nav a::after {
  content: '';
  position: absolute;
  width: 0;
  height: 2px;
  bottom: 0;
  left: 50%;
  background-color: #667eea;
  transition: all 0.3s ease;
}

nav a:hover::after {
  width: 80%;
  left: 10%;
}

nav a.router-link-exact-active {
  color: #667eea;
  font-weight: 600;
}

nav a.router-link-exact-active::after {
  width: 80%;
  left: 10%;
  background-color: #667eea;
}

nav a.router-link-exact-active:hover {
  background-color: transparent;
}

/* 主内容区域样式 */
.main-content {
  padding: 2rem 1.5rem;
  background-color: white;
  margin: 1.5rem;
  border-radius: 12px;
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.05);
}

/* 响应式设计优化 */
@media (max-width: 768px) {
  .top-login-area {
    padding: 0.75rem 0;
  }
  
  .header-login-button {
    padding: 0.5rem 1.5rem;
    font-size: 0.9rem;
  }
  
  nav a {
    padding: 0.5rem 1rem;
    font-size: 1rem;
    margin: 0 0.25rem;
  }
  
  .main-content {
    padding: 1.5rem 1rem;
    margin: 1rem;
    border-radius: 8px;
  }
}

@media (min-width: 1024px) {
  .wrapper {
    display: flex;
    justify-content: center;
  }
}
</style>
